package com.zhuozhengsoft.springbootpageoffice.util;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import org.springframework.util.ResourceUtils;

/**
 * @Author: dong
 * @Date: 2020/11/2 10:39
 * @Version 1.0
 */
@Component
public class GetDirPathUtil {
	
	
	@Resource
	private Environment enviroment ; 
	
	
	private static Environment staticEnviroment;
	
	@PostConstruct
	public void init() {
		staticEnviroment = enviroment;
	}
	
    public static String getDirPath ()  {
        String path;
        try {
        	if(staticEnviroment != null ) {
        		path = staticEnviroment.getProperty("pageoffice.dirPath");
        	}else {
        		path= ResourceUtils.getURL("classpath:").getPath();
        	}
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("没有找到项目根目录!");
        }
        return path;
    }
    
    
    public static String getDirPathStaticDoc() {
    	return GetDirPathUtil.getDirPath() + "/static/doc/"; 
    }
    
}
